//
//  WTFDTLCell.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/18.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "WTFDTLCell.h"
#define CellH 50*fh
@implementation WTFDTLCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubView];
    }
    return self;
}
- (void)initSubView{
    [self addSubview:self.baseView];
    [_baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@0).offset(CellH);
    }];
    [_baseView addSubview:self.doteImageView];
    [_doteImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@15);
        make.width.equalTo(@7);
        make.height.equalTo(@7);
        make.centerY.equalTo(self.baseView.mas_centerY);
    }];
    [_baseView addSubview:self.headerImageView];
    [_headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.doteImageView.mas_right).offset(15);
        make.centerY.equalTo(self.baseView.mas_centerY);
        make.width.equalTo(@40);
        make.height.equalTo(@40);
    }];
    [_baseView addSubview:self.nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerImageView.mas_right).offset(10);
        make.centerY.equalTo(self.baseView.mas_centerY);
        make.width.equalTo(@100);
        make.height.equalTo(@13);
    }];
    [_baseView addSubview:self.rightImageView];
    [_rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@0).offset(-15);
        make.top.equalTo(@0);
        make.width.equalTo(@40);
        make.height.equalTo(@30);
    }];
    [_baseView addSubview:self.timeLabel];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@0).offset(-15);
        make.bottom.equalTo(@0).offset(-10);
        make.left.equalTo(self.baseView.mas_centerX);
        make.height.equalTo(@10);
    }];
    [self addSubview:self.detailLabel];
    [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@15);
        make.bottom.equalTo(@0);
        make.right.equalTo(@0).offset(-15);
        make.top.equalTo(self.baseView.mas_bottom);
    }];
    
}
- (UIView *)baseView{
    if (!_baseView) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = [UIColorChange colorwithHexString:@"#F8F8F8"];
        _baseView = view;
    }
    return _baseView;
}
- (UIImageView *)doteImageView{
    if (!_doteImageView) {
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.image = [UIImage imageNamed:@"notice_buke"];
        _doteImageView = imageView;
    }
    return _doteImageView;
}
- (UIImageView *)headerImageView{
    if (!_headerImageView) {
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.backgroundColor = [UIColor lightGrayColor];
        imageView.layer.cornerRadius = 20;
        imageView.layer.masksToBounds = YES;
        _headerImageView = imageView;
    }
    return _headerImageView;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"王子怡";
        label.textColor = SELECTEDCOLOR;
        label.font = [UIFont systemFontOfSize:14];
        _nameLabel = label;
    }
    return _nameLabel;
}
- (UIButton *)rightImageView{
    if (!_rightImageView) {
        UIButton *imageView = [UIButton buttonWithType:UIButtonTypeCustom];
        [imageView setImage:[UIImage imageNamed:@"menu_buke"] forState:UIControlStateNormal];
        [imageView addTarget:self action:@selector(menuClick:) forControlEvents:UIControlEventTouchUpInside];
        _rightImageView = imageView;
    }
    return _rightImageView;
}
- (void)menuClick:(UIButton *)sender{
   // NSLog(@"弹出菜单");
    UIAlertController * alerC = [UIAlertController alertControllerWithTitle:@"" message:@"操作" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction * ok = [UIAlertAction actionWithTitle:@"分组" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        self.mainBlock(1);
    }];
    [alerC addAction:ok];
    
    UIAlertAction * del = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        self.mainBlock(2);
    }];
    [alerC addAction:del];
    
    UIButton * btn = (UIButton *)sender;
    UIPopoverPresentationController *popPresenter = [alerC popoverPresentationController];
    popPresenter.sourceView = btn;
    popPresenter.sourceRect = btn.bounds;
    
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alerC animated:YES completion:nil];
}





#pragma mark -
- (UILabel *)timeLabel{
    if (!_timeLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"2019-03-27 10:08";
        label.textColor = [UIColorChange colorwithHexString:@"#999999"];
        label.font = [UIFont systemFontOfSize:12];
        label.textAlignment = 2;
        _timeLabel = label;
    }
    return _timeLabel;
}
- (UILabel *)detailLabel{
    if (!_detailLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"虚拟语气做用语境,思考词法语法......";
        label.textColor = [UIColorChange colorwithHexString:@"#999999"];
        label.font = [UIFont systemFontOfSize:12];
        label.textAlignment = 0;
        _detailLabel = label;
    }
    return _detailLabel;
}
@end
